from DingdingAPI import zhuanpai, agree, refuse


def 审批新品采购单(erp_data, 合计金额, taskid, instanceid, conn, cursor):
    allprice = float()
    是否已转交财务审批 = False
    for row in erp_data:
        oldprice = row['oldPrice']
        sumprice = row['sumPrice']
        goodsname = row['goodsName']
        goodscode = row['goodsCode']
        if goodscode in ['PJ008-01', 'OCBHC-01', 'CJDF-01', '0000']:
            zhuanpai(taskid, '存在特殊编码，转交人工识别', conn, cursor)
            break
        if str(oldprice) != '0.0' and goodsname != '采购补差价' and goodsname != '采购运费' and goodscode not in [
            'CGBCJ-001', 'CGBCJ-002', 'CGYF']:
            # 转交财务审核
            zhuanpai(taskid, '旧品申请提交到了新品申请流程了，似乎走错流程了，需要人工判别', conn, cursor)
            是否已转交财务审批 = True
            break
        else:
            allprice += sumprice

    allprice = round(allprice, 2)
    if 是否已转交财务审批:
        # 转交财务审批
        pass
    elif allprice > 20000.00:
        zhuanpai(taskid, '金额超过20000,转人工审核', conn, cursor)
    elif 合计金额 == allprice:
        # 同意
        print(合计金额, allprice, '同意')
        agree(taskid, instanceid, conn, cursor)
    else:
        print(合计金额, allprice, '与ERP金额不一致,不同意')
        # 不同意
        refuse(taskid, instanceid, '与ERP金额不一致', conn, cursor)
